﻿using System.Windows;
using System.Windows.Controls;
using Microsoft.Practices.Composite.Presentation.Commands;

namespace Core.Infrastructure.CommandExtensions
{
    public class ItemsControlDragLeaveCommandBehavior : CommandBehaviorBase<ItemsControl>
    {
        public ItemsControlDragLeaveCommandBehavior(ItemsControl targetObject) : base(targetObject)
        {
            targetObject.DragLeave += new DragEventHandler(TargetObjectDragLeave);
        }

        void TargetObjectDragLeave(object sender, DragEventArgs e)
        {
            var itemsControl = sender as ItemsControl;
            if (itemsControl != null)
            {
                var grid = itemsControl.Items[0] as Grid;
                if (grid != null)
                    CommandParameter = grid.Children[0];
            }
            base.ExecuteCommand();
        }
    }
}
